package com.songlanyun.modules.faq.service.impl;

import cn.hutool.core.map.MapUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.utils.Query;

import com.songlanyun.modules.faq.dao.SysFaqDao;
import com.songlanyun.modules.faq.entity.SysFaqEntity;
import com.songlanyun.modules.faq.service.SysFaqService;


@Service("sysFaqService")
public class SysFaqServiceImpl extends ServiceImpl<SysFaqDao, SysFaqEntity> implements SysFaqService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String title = MapUtil.getStr(params, "title");
        LambdaQueryWrapper<SysFaqEntity> wrapper = new LambdaQueryWrapper<>();
        if(StringUtils.isNotBlank(title))
        {
            wrapper.like(StringUtils.isNotBlank(title), SysFaqEntity::getTitle, title)
                    .or().like(StringUtils.isNotBlank(title), SysFaqEntity::getContent, title);
        }
        wrapper.orderByAsc(SysFaqEntity::getSort).orderByDesc(SysFaqEntity::getCreateTime);

        IPage<SysFaqEntity> page = this.page(
                new Query<SysFaqEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

}